// Place and render all sprites.


#ifndef LIGHTY_SPRITES_LOADER_H
#define LIGHTY_SPRITES_LOADER_H

#include <GL/glew.h>
#include <SDL_image.h>
#include <string>
#include "Lighty_Debug.h"
#include "Lighty_Hitbox.h"
#include "Lighty_Window_Handler.h"

const long int MaxPreloadSprite=500;

SDL_Surface* Preloaded_Cache_Sprite[MaxPreloadSprite]={NULL};
SDL_Texture* Preloaded_Sprite[MaxPreloadSprite]={NULL};

class Preload_ImgContainer{
	
  public:
  
    std::string spritename;
    bool istaken=false;
	
};

Preload_ImgContainer PreloadContainer[MaxPreloadSprite];

int Lighty_Load_PreloadSprite(std::string name){
	
  bool found=false;
	
  for(int i=0;i<MaxPreloadSprite;i++){
	  
    if(PreloadContainer[i].spritename==name){
		
	  if(Preloaded_Sprite[i]==NULL){
		  
	    Preloaded_Sprite[i]=SDL_CreateTextureFromSurface(renderer, Preloaded_Cache_Sprite[i]);
	    SDL_FreeSurface(Preloaded_Cache_Sprite[i]); // À vérifier, permet de libérer de la mémoire en utilisation.
	    Preloaded_Cache_Sprite[i]=NULL;
		  
	  }
	  	
	  if(SDL_RenderCopy(renderer, Preloaded_Sprite[i], NULL, NULL)==-1){
		
		Lighty_PrintDebug("Image error : Image couldnt be loaded !");
	    return 1;	
		  
	  }
	  
	  SDL_RenderPresent(renderer);
	  found=true;
	  i=MaxPreloadSprite;
		
	}
	  
  }
  
  if(!found){
	  
	Lighty_PrintDebug("Image error : Name hasn't be found");  
    return 1;
	  
  }
  
  return 0;
	
}

#endif
